﻿var MainScene = cc.Scene.extend(
{
    playLayer: null,
    onEnter: function () {
        this._super();
        var size = cc.director.getWinSize();
        var bg = new cc.Sprite("res/bg.jpg");
        bg.x = size.width / 2;
        bg.y = size.height / 2;
        this.addChild(bg);

        var clip = this.clip();
        this.addChild(clip);

        this.playLayer = new PlayLayer();
        this.playLayer.y = (size.height - 64 * 10) / 2;
        this.playLayer.x = (size.width - 64 * 10) / 2;

        var uiLayer = new UILayer(this.playLayer);
        this.addChild(uiLayer, 3);
        clip.addChild(this.playLayer);


    },
    clip: function () {
        var size = cc.director.getWinSize();
        var clipNode = new cc.ClippingNode();
        var stencil = new cc.DrawNode();
        stencil.drawRect(cc.p(0, 0), cc.p(640, 640), cc.color(0, 0, 0), 1, cc.color(0, 0, 0));
        stencil.x = (size.width - (Constant.CANDY_MAXSIZE * 64)) / 2;
        stencil.y = (size.height - (Constant.CANDY_MAXSIZE * 64)) / 2;
        clipNode.stencil = stencil;
        return clipNode;
    }
}
);
var UILayer = cc.Layer.extend({
    txtScore: null,
    playerLayer: null,
    txtStep: null,
    ctor: function (playerLayer) {
        this._super();
        var size = cc.director.getWinSize();
        //var bg = new cc.Sprite("res/bg.jpg");
        //bg.x = size.width / 2;
        //bg.y = size.height / 2;
        //this.addChild(bg);
        this.playerLayer = playerLayer;
        var lblLevel = new cc.LabelTTF("等级", "Arial", 38);
        lblLevel.setColor(cc.color(0, 0, 0, 255));
        lblLevel.x = 150;
        lblLevel.y = size.height - 30;
        this.addChild(lblLevel);
        var txtLevel = new cc.LabelTTF("0", "Arial", 38);
        txtLevel.setColor(cc.color(0, 0, 0, 255));
        txtLevel.x = 150;
        txtLevel.y = size.height - 70;
        this.addChild(txtLevel);

        var lblScore = new cc.LabelTTF("分数", "Arial", 38);
        lblScore.setColor(cc.color(0, 0, 0, 255));
        lblScore.x = 350;
        lblScore.y = size.height - 30;
        this.addChild(lblScore);
        this.txtScore = new cc.LabelTTF("0", "Arial", 38);
        this.txtScore.setColor(cc.color(0, 0, 0, 255));
        this.txtScore.x = 350;
        this.txtScore.y = size.height - 70;
        this.addChild(this.txtScore);

        var lblStep = new cc.LabelTTF("步骤", "Arial", 38);
        lblStep.setColor(cc.color(0, 0, 0, 255));
        lblStep.x = 550;
        lblStep.y = size.height - 30;
        this.addChild(lblStep);
        this.txtStep = new cc.LabelTTF("0", "Arial", 38);
        this.txtStep.setColor(cc.color(0, 0, 0, 255));
        this.txtStep.x = 550;
        this.txtStep.y = size.height - 70;
        this.addChild(this.txtStep);


        this.scheduleUpdate();
    },
    update: function () {
        this.txtScore.setString(this.playerLayer.score);
        this.txtStep.setString(this.playerLayer.steps);

    }
});

